package agents.interaction;

import interfaces.ActionInterface;

import interfaces.impl.HumanInteraction;

import java.awt.Graphics;
import java.util.ArrayList;

import actions.ActionTeleport;

import objects.WorldObject;
import universe.Universe;
import extra.Position;
import constants.*;

public class InteractionMoveObject extends HumanInteraction{
	
	
	private WorldObject objectToMove=null;
	private Position positionToMove=null;
	private ActionTeleport actionTeleport;
	
	
	public InteractionMoveObject(){
		this.id=Constants.AGENT_HUMAN_INTERACTION_MOVE_OBJECT;
		
		listActions = new ArrayList<ActionInterface>();
		
		actionTeleport= new ActionTeleport(priority);
		listActions.add(actionTeleport);
		
		numParameters=0;
		totalParameters=2;
		
		
		isActive=false;
	}
	

	@Override
	public void update(WorldObject object, Universe worldI, double time) {
		if(!isActive){
			//System.out.println("No estoy activo");
			return;
		}
		if(!canUpdate(object)){
			System.out.println("Me falta alguna accion para poder actuar");
			return;
		}
		
		
		//System.out.println("ESTOY ACTIVO MOVE OBJECT X " + objectToMove.getObjectReference());
		
		actionTeleport.setPosition(positionToMove);
		actionTeleport.setSource(object);
		actionTeleport.setTarget(objectToMove);
		object.setImmediatlyActionToDo(actionTeleport);
		
		
		objectToMove = null;
		isActive=false;
	}

	@Override
	public void paint(Graphics g, WorldObject object) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "Move Object";
	}

	@Override
	public void setName(String name) {
		this.name=name;
		
	}


	@Override
	public boolean setParameter(String parameter,Universe universe) {
		
		String str[] = parameter.split("/");
		
		String position[] = str[3].split(";");
		
		positionToMove= new Position();
		positionToMove.setX(Double.parseDouble(position[0]));
		positionToMove.setY(Double.parseDouble(position[1]));
		
		int objID = Integer.parseInt(str[2]);
		objectToMove = universe.getObject(objID);
		if(objectToMove!=null){
			isActive=true;
			return true;
		}
		
		return false;	
	}


	@Override
	public String getParameters() {
		String res= new String();
		res=Constants.PARAMETER_OBJECT+";"+ constants.Constants.PARAMETER_POSITION;
		return res;
	}
	
	

}
